package io;

import org.junit.Test;
import sun.lwawt.macosx.CSystemTray;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author wangzhipeng
 * @Date 2020-08-19 4:13 下午
 * @Description
 * 演示字符流
 *  1、字符流是以字符为单位进行读取和写入的，用于「文本」的读写
 *  2、字符流的根流
 *      输出流：Writer
 *      输入流：Reader
 */
public class CharIODemo {
    /**
     * 使用文件流字符流
     */
    @Test
    public void demo() throws IOException{
        FileReader reader = new FileReader("/Users/wangzhipeng/Desktop/a.txt");

        int content = reader.read();
        while (content != -1){
            System.out.print((char)content);
            content = reader.read();
        }
        reader.close();

    }


    /**
     * 复制图片 不行的
     * @throws Exception
     */
    @Test
    public void demo3() throws Exception{
        //创建输入输出流
        FileReader reader = new FileReader("/Users/wangzhipeng/Desktop/蔬菜之乡.png");
        FileWriter writer = new FileWriter("/Users/wangzhipeng/Desktop/222.png");

        int content = reader.read();
        while (content != -1 ){
            writer.write(content);
            content = reader.read();
        }
        reader.close();
        writer.close();
    }
}
